import time

from selenium.webdriver.common.by import By

from base.BasePage import BasePage
from common.DriverTools import DriverTools
from page.HomePage import HomePage


class LoginPage(BasePage):
    # 初始化实例属性
    def __init__(self):
        # 继承基类包中封装方法，查找元素和输入内容，可以直接调用基类方法
        super().__init__()
        # 用户名
        self.user=(By.ID,'username')
        # 密码
        self.password=(By.ID,'password')
        # 验证码
        self.verify_code=(By.ID,'verify_code')
        # 登录按钮
        self.login_btn=(By.CLASS_NAME,'J-login-submit')

    # 定义登录方法
    def login(self,user,pwd,code):
        self.input(self.find_el(self.user),user)
        self.input(self.find_el(self.password), pwd)
        self.input(self.find_el(self.verify_code), code)
        self.find_el(self.login_btn).click()

if __name__ == '__main__':
    driver=DriverTools.get_driver()
    driver.get("http://hmshop-test.itheima.net/")
    HomePage().goto_login_page()
    time.sleep(2)
    LoginPage().login("13012345678","123456","8888")
    time.sleep(2)
    driver.quit()